//********************************************************************
// 
//  file:  PurchasingManagement.cs
// 
//  (C) Copyright 2010, Diomede Corporation
//  All rights reserved
// 
//  Use, modification, and distribution is subject to   
//  the New BSD License (See accompanying file license.txt).
// 
//********************************************************************

using System;
using System.Collections.Generic;
using data.diomedestorage.com;
using Diomede.SDK.Enums;

namespace Diomede.SDK
{
    #region Interface

    /// <summary>
    /// Interface for all Purchasing functions
    /// </summary>
    public interface IPurchasingManagement
    {
        /// <summary>
        /// Returns all products.
        /// </summary>
        /// <returns>Will return Products Execution Result, see <see cref="ProductsExecResult"/>.</returns>
        /// <example>
        /// <code>
        ///  public void GetAllProductsSample()
        /// {
        ///    ISession session = new Session();
        ///    IPurchasingManagement pm = session as IPurchasingManagement;
        ///    ProductsExecResult result = pm.GetAllProducts();
        ///
        ///    if (result.Status != ExecutionResults.Success)
        ///    {
        ///        throw new Exception("Fails to get all Products.");
        ///    }
        ///    else
        ///    {
        ///        Console.WriteLine("All Products successfully retrieved.");
        ///    }
        /// }
        /// </code>
        /// <code lang="VB.NET">
        /// Public Sub GetAllProductsSample()
        ///    Dim session As ISession = New Session()
        ///    Dim pm As IPurchasingManagement = TryCast(session, IPurchasingManagement)
        ///    Dim result As ProductsExecResult = pm.GetAllProducts()
        ///
        ///    If result.Status &lt;&gt; ExecutionResults.Success Then
        ///        Throw New Exception("Fails to get all Products.")
        ///    Else
        ///        Console.WriteLine("All Products successfully retrieved.")
        ///    End If
        ///
        /// End Sub
        /// </code>
        /// </example>
        ProductsExecResult GetAllProducts();

        /// <summary>
        /// Returns all products that belong to the user.
        /// </summary>
        /// <returns>Will return Users Products Execution Result, see <see cref="UsersProductsExecResult"/>.</returns>
        /// <example>
        /// <code>
        /// public void GetMyProductsSample()
        ///{
        ///    ISession session = new Session();
        ///
        ///    LoginSampleUser(session);
        ///
        ///    IPurchasingManagement pm = session as IPurchasingManagement;
        ///    ProductsExecResult getproducts = pm.GetAllProducts();
        ///
        ///    Product productToPurchase = getproducts.Products[0];
        ///
        ///    ProductsExecResult purchasePrudResult = pm.PurchaseProduct(productToPurchase.ProductID);
        ///
        ///    if (pm.GetMyProducts().Status != ExecutionResults.Success)
        ///    {
        ///        throw new Exception("Fails to retrieve my Products.");
        ///    }
        ///    else
        ///    {
        ///        Console.WriteLine("My Products successfully retrieved.");
        ///    }
        /// }
        /// </code>
        /// <code lang="VB.NET">
        /// Public Sub GetMyProductsSample()
        ///    Dim session As ISession = New Session()
        ///
        ///    LoginSampleUser(session)
        ///
        ///    Dim pm As IPurchasingManagement = TryCast(session, IPurchasingManagement)
        ///    Dim getproducts As ProductsExecResult = pm.GetAllProducts()
        ///
        ///    Dim productToPurchase As Product = getproducts.Products(0)
        ///
        ///    Dim purchasePrudResult As ProductsExecResult = pm.PurchaseProduct(productToPurchase.ProductID)
        ///
        ///    If pm.GetMyProducts().Status &lt;&gt; ExecutionResults.Success Then
        ///        Throw New Exception("Fails to retrieve my Products.")
        ///    Else
        ///        Console.WriteLine("My Products successfully retrieved.")
        ///    End If
        /// End Sub
        /// </code>
        /// </example>
        UsersProductsExecResult GetMyProducts();

        /// <summary>
        /// Processes the purchasing of products.
        /// </summary>
        /// <param name="productID">Product ID.</param>
        /// <returns>Will return Products Execution Result, see <see cref="ProductsExecResult"/>.</returns>
        /// <example>
        /// <code>
        /// public void PuchaseProductsSample()
        /// {
        ///    ISession session = new Session();
        ///
        ///    LoginSampleUser(session);
        ///
        ///    IPurchasingManagement pm = session as IPurchasingManagement;
        ///    ProductsExecResult getproducts = pm.GetAllProducts();
        ///
        ///    Product productToPurchase = getproducts.Products[0];
        ///
        ///    if (pm.PurchaseProduct(productToPurchase.ProductID).Status != ExecutionResults.Success)
        ///    {
        ///        throw new Exception("Fails to purchase Product.");
        ///    }
        ///    else
        ///    {
        ///        Console.WriteLine("Product succesfully purchased.");
        ///    }
        ///
        /// }
        /// </code>
        /// <code lang="VB.NET">
        /// Public Sub PuchaseProductsSample()
        ///    Dim session As ISession = New Session()
        ///
        ///    LoginSampleUser(session)
        ///
        ///    Dim pm As IPurchasingManagement = TryCast(session, IPurchasingManagement)
        ///    Dim getproducts As ProductsExecResult = pm.GetAllProducts()
        ///
        ///    Dim productToPurchase As Product = getproducts.Products(0)
        ///
        ///    If pm.PurchaseProduct(productToPurchase.ProductID).Status &lt;&gt; ExecutionResults.Success Then
        ///        Throw New Exception("Fails to purchase Product.")
        ///    Else
        ///        Console.WriteLine("Product succesfully purchased.")
        ///    End If
        ///
        /// End Sub
        /// </code>
        /// </example>
        ProductsExecResult PurchaseProduct(int productID);

        /// <summary>
        /// Cancel the purchased products.
        /// </summary>
        /// <param name="userProductID">Product ID.</param>
        /// <returns>Will return Products Execution Result, see <see cref="ProductsExecResult"/>.</returns>
        /// <example>
        /// <code>
        /// public void CancelProductsSample()
        /// {
        ///    ISession session = new Session();
        ///
        ///    LoginSampleUser(session);
        ///
        ///    IPurchasingManagement pm = session as IPurchasingManagement;
        ///    ProductsExecResult getproducts = pm.GetAllProducts();
        ///
        ///    Product productToPurchase = getproducts.Products[0];
        ///
        ///    ProductsExecResult purchasePrudResult = pm.PurchaseProduct(productToPurchase.ProductID);
        ///
        ///    if (pm.CancelProduct(pm.GetMyProducts().UserProducts[0].userProductID).Status != ExecutionResults.Success)
        ///    {
        ///        throw new Exception("Fails to cancel Product.");
        ///    }
        ///    else
        ///    {
        ///        Console.WriteLine("My Product successfully cancelled.");
        ///    }
        ///
        /// }
        /// </code>
        /// <code lang="VB.NET">
        /// Public Sub CancelProductsSample()
        ///    Dim session As ISession = New Session()
        ///
        ///    LoginSampleUser(session)
        ///
        ///    Dim pm As IPurchasingManagement = TryCast(session, IPurchasingManagement)
        ///    Dim getproducts As ProductsExecResult = pm.GetAllProducts()
        ///
        ///    Dim productToPurchase As Product = getproducts.Products(0)
        ///
        ///    Dim purchasePrudResult As ProductsExecResult = pm.PurchaseProduct(productToPurchase.ProductID)
        ///
        ///    If pm.CancelProduct(pm.GetMyProducts().UserProducts(0).userProductID).Status &lt;&gt; ExecutionResults.Success Then
        ///        Throw New Exception("Fails to cancel Product.")
        ///    Else
        ///        Console.WriteLine("My Product successfully cancelled.")
        ///    End If
        ///
        /// End Sub
        /// </code>
        /// </example>
        ProductsExecResult CancelProduct(int userProductID);

        /// <summary>
        /// Returns all the Contracts.
        /// </summary>
        /// <returns>Will return Contracts Execution Result, see <see cref="ContractsExecResult"/>.</returns>
        /// <example>
        /// <code>
        /// public void GetAllContractsSample()
        /// {
        ///    ISession session = new Session();
        ///    IPurchasingManagement pm = session as IPurchasingManagement;
        ///    ContractsExecResult result = pm.GetAllContracts();
        ///
        ///    if (result.Status != ExecutionResults.Success)
        ///    {
        ///        throw new Exception("Fails to get all Contracts.");
        ///    }
        ///    else
        ///    {
        ///        Console.WriteLine("All Contracts successfully retrieved.");
        ///    }
        ///
        /// }
        /// </code>
        /// <code lang="VB.NET">
        /// Public Sub GetAllContractsSample()
        ///    Dim session As ISession = New Session()
        ///    Dim pm As IPurchasingManagement = TryCast(session, IPurchasingManagement)
        ///    Dim result As ContractsExecResult = pm.GetAllContracts()
        ///
        ///    If result.Status &lt;&gt; ExecutionResults.Success Then
        ///        Throw New Exception("Fails to get all Contracts.")
        ///    Else
        ///        Console.WriteLine("All Contracts successfully retrieved.")
        ///    End If
        ///
        /// End Sub
        /// </code>
        /// </example>
        ContractsExecResult GetAllContracts();

        /// <summary>
        /// Returns all contracts that belong to the user.
        /// </summary>
        /// <returns>Will return Users Contracts Execution Result, see <see cref="UsersContractsExecResult"/>.</returns>
        /// <example>
        /// <code>
        /// public void GetMyContractsSample()
        /// {
        ///    ISession session = new Session();
        ///
        ///    LoginSampleUser(session);
        ///
        ///    IPurchasingManagement pm = session as IPurchasingManagement;
        ///    ContractsExecResult getContracts = pm.GetAllContracts();
        ///
        ///    Contract contractToPurchase = getContracts.Contracts[0];
        ///
        ///    ContractsExecResult purchasePrudResult = pm.PurchaseContract(contractToPurchase.ContractID);
        ///
        ///    if (pm.GetMyContracts().Status != ExecutionResults.Success)
        ///    {
        ///        throw new Exception("Fails to retrieve my Contracts.");
        ///    }
        ///    else
        ///    {
        ///        Console.WriteLine("My Contracts successfully retrieved.");
        ///    }
        /// }
        /// </code>
        /// <code lang="VB.NET">
        /// Public Sub GetMyContractsSample()
        ///    Dim session As ISession = New Session()
        ///
        ///    LoginSampleUser(session)
        ///
        ///    Dim pm As IPurchasingManagement = TryCast(session, IPurchasingManagement)
        ///    Dim getContracts As ContractsExecResult = pm.GetAllContracts()
        ///
        ///    Dim contractToPurchase As Contract = getContracts.Contracts(0)
        ///
        ///    Dim purchasePrudResult As ContractsExecResult = pm.PurchaseContract(contractToPurchase.ContractID)
        ///
        ///    If pm.GetMyContracts().Status &lt;&gt; ExecutionResults.Success Then
        ///        Throw New Exception("Fails to retrieve my Contracts.")
        ///    Else
        ///        Console.WriteLine("My Contracts successfully retrieved.")
        ///    End If
        /// End Sub
        /// </code>
        /// </example>
        UsersContractsExecResult GetMyContracts();

        /// <summary>
        /// Processes the purchasing of contracts.
        /// </summary>
        /// <param name="contractID">ID of the contract.</param>
        /// <returns>Will return Contracts Execution Result, see <see cref="ContractsExecResult"/>.</returns>
        /// <example>
        /// <code>
        /// public void PuchaseContractsSample()
        /// {
        ///    ISession session = new Session();
        ///
        ///    LoginSampleUser(session);
        ///
        ///    IPurchasingManagement pm = session as IPurchasingManagement;
        ///    ContractsExecResult getContracts = pm.GetAllContracts();
        ///
        ///    Contract contractToPurchase = getContracts.Contracts[0];
        ///
        ///    if (pm.PurchaseContract(contractToPurchase.ContractID).Status != ExecutionResults.Success)
        ///    {
        ///        throw new Exception("Fails to purchase Contract.");
        ///    }
        ///    else
        ///    {
        ///        Console.WriteLine("Contract succesfully purchased.");
        ///    }
        ///
        /// }
        /// </code>
        /// <code lang="VB.NET">
        /// Public Sub PuchaseContractsSample()
        ///    Dim session As ISession = New Session()
        ///
        ///    LoginSampleUser(session)
        ///
        ///    Dim pm As IPurchasingManagement = TryCast(session, IPurchasingManagement)
        ///    Dim getContracts As ContractsExecResult = pm.GetAllContracts()
        ///
        ///    Dim contractToPurchase As Contract = getContracts.Contracts(0)
        ///
        ///    If pm.PurchaseContract(contractToPurchase.ContractID).Status &lt;&gt; ExecutionResults.Success Then
        ///        Throw New Exception("Fails to purchase Contract.")
        ///    Else
        ///        Console.WriteLine("Contract succesfully purchased.")
        ///    End If
        ///
        /// End Sub
        /// </code>
        /// </example>
        ContractsExecResult PurchaseContract(int contractID);

        /// <summary>
        /// Cancel the purchased contracts.
        /// </summary>
        /// <param name="userContractID">Contract ID.</param>
        /// <returns>Will return Contracts Execution Result, see <see cref="ContractsExecResult"/>.</returns>
        /// <example>
        /// <code>
        ///  public void CancelContractsSample()
        /// {
        ///    ISession session = new Session();
        ///
        ///    LoginSampleUser(session);
        ///
        ///    IPurchasingManagement pm = session as IPurchasingManagement;
        ///    ContractsExecResult getContracts = pm.GetAllContracts();
        ///
        ///    Contract contractToPurchase = getContracts.Contracts[0];
        ///
        ///    ContractsExecResult purchasePrudResult = pm.PurchaseContract(contractToPurchase.ContractID);
        ///
        ///    if (pm.CancelContract(pm.GetMyContracts().UserContracts[0].userContractID).Status != ExecutionResults.Success)
        ///    {
        ///        throw new Exception("Fails to cancel Contracts.");
        ///    }
        ///    else
        ///    {
        ///        Console.WriteLine("My Contract successfully cancelled.");
        ///    }
        ///
        /// }
        /// </code>
        /// <code lang="VB.NET">
        /// Public Sub CancelContractsSample()
        ///    Dim session As ISession = New Session()
        ///
        ///    LoginSampleUser(session)
        ///
        ///    Dim pm As IPurchasingManagement = TryCast(session, IPurchasingManagement)
        ///    Dim getContracts As ContractsExecResult = pm.GetAllContracts()
        ///
        ///    Dim contractToPurchase As Contract = getContracts.Contracts(0)
        ///
        ///    Dim purchasePrudResult As ContractsExecResult = pm.PurchaseContract(contractToPurchase.ContractID)
        ///
        ///    If pm.CancelContract(pm.GetMyContracts().UserContracts(0).userContractID).Status &lt;&gt; ExecutionResults.Success Then
        ///        Throw New Exception("Fails to cancel Contracts.")
        ///    Else
        ///        Console.WriteLine("My Contract successfully cancelled.")
        ///    End If
        ///
        /// End Sub
        /// </code>
        /// </example>
        ContractsExecResult CancelContract(long userContractID);
    
        /////// <summary>
        /////// Returns all the supports.
        /////// </summary>
        /////// <returns>Will return Supports Execution Result, see <see cref="SupportsExecResult"/>.</returns>
        /////// <example>
        /////// <code>
        /////// public void GetAllSupportsSample()
        /////// {
        ///////    ISession session = new Session();
        ///////    IPurchasingManagement pm = session as IPurchasingManagement;
        ///////    SupportsExecResult result = pm.GetAllSupports();
        ///////
        ///////    if (result.Status != ExecutionResults.Success)
        ///////    {
        ///////        throw new Exception("Fails to get all Supports.");
        ///////    }
        ///////    else
        ///////    {
        ///////        Console.WriteLine("All Supports successfully retrieved.");
        ///////    }
        ///////
        /////// }
        /////// </code>
        /////// <code lang="VB.NET">
        /////// Public Sub GetAllSupportsSample()
        ///////    Dim session As ISession = New Session()
        ///////    Dim pm As IPurchasingManagement = TryCast(session, IPurchasingManagement)
        ///////    Dim result As SupportsExecResult = pm.GetAllSupports()
        ///////
        ///////    If result.Status &lt;&gt; ExecutionResults.Success Then
        ///////        Throw New Exception("Fails to get all Supports.")
        ///////    Else
        ///////        Console.WriteLine("All Supports successfully retrieved.")
        ///////    End If
        ///////
        /////// End Sub
        /////// </code>
        /////// </example>
        ////SupportsExecResult GetAllSupports();

        ///// <summary>
        ///// Returns the supports that belong to the user.
        ///// </summary>
        ///// <returns>Will return Users Support Execution Result, see <see cref="UsersSupportsExecResult"/>.</returns>
        ///// <example>
        ///// <code>
        ///// public void GetMySupportsSample()
        ///// {
        /////    ISession session = new Session();
        /////
        /////    LoginSampleUser(session);
        /////
        /////    IPurchasingManagement pm = session as IPurchasingManagement;
        /////    SupportsExecResult getSupports = pm.GetAllSupports();
        /////
        /////    Support supportToPurchase = getSupports.Supports[0];
        /////
        /////    SupportsExecResult purchasePrudResult = pm.PurchaseSupport(supportToPurchase.supportID);
        /////
        /////    if (pm.GetMySupports().Status != ExecutionResults.Success)
        /////    {
        /////        throw new Exception("Fails to retrieve my Supports.");
        /////    }
        /////    else
        /////    {
        /////        Console.WriteLine("My Supports successfully retrieved.");
        /////    }
        ///// }
        ///// </code>
        ///// <code lang="VB.NET">
        ///// Public Sub GetMySupportsSample()
        /////    Dim session As ISession = New Session()
        /////
        /////    LoginSampleUser(session)
        /////
        /////    Dim pm As IPurchasingManagement = TryCast(session, IPurchasingManagement)
        /////    Dim getSupports As SupportsExecResult = pm.GetAllSupports()
        /////
        /////    Dim supportToPurchase As Support = getSupports.Supports(0)
        /////
        /////    Dim purchasePrudResult As SupportsExecResult = pm.PurchaseSupport(supportToPurchase.supportID)
        /////
        /////    If pm.GetMySupports().Status &lt;&gt; ExecutionResults.Success Then
        /////        Throw New Exception("Fails to retrieve my Supports.")
        /////    Else
        /////        Console.WriteLine("My Supports successfully retrieved.")
        /////    End If
        ///// End Sub
        ///// </code>
        ///// </example>
        //UsersSupportsExecResult GetMySupports();

        ///// <summary>
        ///// Processes the purchasing of supports.
        ///// </summary>
        ///// <param name="supportID">ID of the support.</param>
        ///// <returns>Will return Products Execution Result, see <see cref="ProductsExecResult"/>.</returns>
        ///// <example>
        ///// <code>
        ///// public void PuchaseSupportsSample()
        ///// {
        /////    ISession session = new Session();
        /////
        /////    LoginSampleUser(session);
        /////
        /////    IPurchasingManagement pm = session as IPurchasingManagement;
        /////    SupportsExecResult getSupports = pm.GetAllSupports();
        /////
        /////    Support supportToPurchase = getSupports.Supports[0];
        /////
        /////    if (pm.PurchaseContract(supportToPurchase.supportID).Status != ExecutionResults.Success)
        /////    {
        /////        throw new Exception("Fails to purchase Support.");
        /////    }
        /////    else
        /////    {
        /////        Console.WriteLine("Support succesfully purchased.");
        /////    }
        /////
        /////}
        ///// </code>
        ///// <code lang="VB.NET">
        ///// Public Sub PuchaseSupportsSample()
        /////    Dim session As ISession = New Session()
        /////
        /////    LoginSampleUser(session)
        /////
        /////    Dim pm As IPurchasingManagement = TryCast(session, IPurchasingManagement)
        /////    Dim getSupports As SupportsExecResult = pm.GetAllSupports()
        /////
        /////    Dim supportToPurchase As Support = getSupports.Supports(0)
        /////
        /////    If pm.PurchaseContract(supportToPurchase.supportID).Status &lt;&gt; ExecutionResults.Success Then
        /////        Throw New Exception("Fails to purchase Support.")
        /////    Else
        /////        Console.WriteLine("Support succesfully purchased.")
        /////    End If
        /////
        ///// End Sub
        ///// </code>
        ///// </example>
        //SupportsExecResult PurchaseSupport(int productID);

        ///// <summary>
        ///// Cancel the purchased supports.
        ///// </summary>
        ///// <param name="userSupportID">Support ID.</param>
        ///// <returns>Will return Supports Execution Result, see <see cref="SupportsExecResult"/>.</returns>
        ///// <example>
        ///// <code>
        ///// public void CancelSupportsSample()
        ///// {
        /////    ISession session = new Session();
        /////
        /////    LoginSampleUser(session);
        /////
        /////    IPurchasingManagement pm = session as IPurchasingManagement;
        /////    SupportsExecResult getSupports = pm.GetAllSupports();
        /////
        /////    Support supportToPurchase = getSupports.Supports[0];
        /////
        /////    SupportsExecResult purchasePrudResult = pm.PurchaseSupport(supportToPurchase.supportID);
        /////
        /////    if (pm.CancelContract(pm.GetMySupports().UserSupports[0].userSupportID).Status != ExecutionResults.Success)
        /////    {
        /////        throw new Exception("Fails to cancel Supports.");
        /////    }
        /////    else
        /////    {
        /////        Console.WriteLine("My supports Successfully cancelled.");
        /////    }
        /////
        /////}
        ///// </code>
        ///// <code lang="VB.NET">
        ///// Public Sub CancelSupportsSample()
        /////    Dim session As ISession = New Session()
        /////
        /////    LoginSampleUser(session)
        /////
        /////    Dim pm As IPurchasingManagement = TryCast(session, IPurchasingManagement)
        /////    Dim getSupports As SupportsExecResult = pm.GetAllSupports()
        /////
        /////    Dim supportToPurchase As Support = getSupports.Supports(0)
        /////
        /////    Dim purchasePrudResult As SupportsExecResult = pm.PurchaseSupport(supportToPurchase.supportID)
        /////
        /////    If pm.CancelContract(pm.GetMySupports().UserSupports(0).userSupportID).Status &lt;&gt; ExecutionResults.Success Then
        /////        Throw New Exception("Fails to cancel Supports.")
        /////    Else
        /////        Console.WriteLine("My supports successfully cancelled.")
        /////    End If
        /////
        ///// End Sub
        ///// </code>
        ///// </example>
        //SupportsExecResult CancelSupport(int userSupportID);

    }

    #endregion

    #region Implementations

    /// <summary>
    /// Object that will be returned which contains Product Execution Results. 
    /// </summary>
    public class ProductsExecResult : IExecResult
    {
        /// <summary>
        /// Create new instance of ProductsExecResult.
        /// </summary>
        public ProductsExecResult()
        {
        }

        /// <summary>
        /// Create new instance of ProductsExecResult, with status and message as parameters.
        /// </summary>
        /// <param name="status">Returned status.</param>
        /// <param name="message">Returned message.</param>
        public ProductsExecResult(ExecutionResults status, string message)
        {
            this.status = status;
            this.message = message;
        }

        /// <summary>
        /// Create new instance of ProductsExecResult, with status, message and products as parameters.
        /// </summary>
        /// <param name="status">Returned status.</param>
        /// <param name="message">Returned message.</param>
        /// <param name="products">Returned products.</param>
        public ProductsExecResult(ExecutionResults status, string message, Product[] products)
        {
            this.status = status;
            this.message = message;
            this.products = new List<Product>(products);
        }

        /// <summary>
        /// Create new instance of ProductsExecResult, with an Exception as parameter.
        /// </summary>
        /// <param name="ex">Returned exception.</param>
        public ProductsExecResult(Exception ex)
        {
            status = ExecutionResults.Failed;
            message = ex.Message;
        }


        private List<Product> products;

        /// <summary>
        /// Holders of returned products.
        /// </summary>
        public List<Product> Products
        {
            get { return products; }
            set { products = value; }
        }


        #region IExecResult Members

        ExecutionResults status;
        /// <summary>
        /// IExecResult.Status implementation, see <see cref="IExecResult.Status">IExecResult.Status</see> for more information.
        /// </summary>
        public ExecutionResults Status
        {
            get { return status; }
            set { status = value; }
        }

        string message;
        /// <summary>
        /// IExecResult.Message implementation, see <see cref="IExecResult.Message">IExecResult.Message</see> for more information.
        /// </summary>
        public string Message
        {
            get { return message; }
            set { message = value; }
        }

        #endregion
    }

    /// <summary>
    /// Object that will be returned which contains Users Products Execution Results. 
    /// </summary>
    public class UsersProductsExecResult : IExecResult
    {
        /// <summary>
        /// Create new instance of UsersProductsExecResult.
        /// </summary>
        public UsersProductsExecResult()
        {
        }

        /// <summary>
        /// Create new instance of UsersProductsExecResult, with status and message as parameters.
        /// </summary>
        /// <param name="status">Returned Status.</param>
        /// <param name="message">Returned Message.</param>
        public UsersProductsExecResult(ExecutionResults status, string message)
        {
            this.status = status;
            this.message = message;
        }

        /// <summary>
        /// Create new instance of UsersProductsExecResult, with status, message and products as parameters.
        /// </summary>
        /// <param name="status">Returned status.</param>
        /// <param name="message">Returned message.</param>
        /// <param name="products">Returned products.</param>
        public UsersProductsExecResult(ExecutionResults status, string message, UserProduct[] products)
        {
            this.status = status;
            this.message = message;
            this.userProducts = new List<UserProduct>(products);
        }

        /// <summary>
        /// Create new instance of ProductUsersProductsExecResultsExecResult, with an Exception as parameter.
        /// </summary>
        /// <param name="ex">Returned Exception.</param>
        public UsersProductsExecResult(Exception ex)
        {
            status = ExecutionResults.Failed;
            message = ex.Message;
        }


        private List<UserProduct> userProducts;
        /// <summary>
        /// Holder of returned products.
        /// </summary>
        public List<UserProduct> UserProducts
        {
            get { return userProducts; }
            set { userProducts = value; }
        }

        #region IExecResult Members

        ExecutionResults status;
        /// <summary>
        /// IExecResult.Status implementation, see <see cref="IExecResult.Status">IExecResult.Status</see> for more information.
        /// </summary>
        public ExecutionResults Status
        {
            get { return status; }
            set { status = value; }
        }

        string message;
        /// <summary>
        /// IExecResult.Message implementation, see <see cref="IExecResult.Message">IExecResult.Message</see> for more information.
        /// </summary>
        public string Message
        {
            get { return message; }
            set { message = value; }
        }

        #endregion

    }

    /// <summary>
    /// Object that will be returned which contains Contract Execution Results.
    /// </summary>
    public class ContractsExecResult : IExecResult
    {
        /// <summary>
        /// Create new instance of ContractsExecResult.
        /// </summary>
        public ContractsExecResult()
        {
        }

        /// <summary>
        /// Create new instance of ContractsExecResult, with status and message as parameters.
        /// </summary>
        /// <param name="status">Returned status.</param>
        /// <param name="message">Returned message.</param>
        public ContractsExecResult(ExecutionResults status, string message)
        {
            this.status = status;
            this.message = message;
        }

        /// <summary>
        /// Create new instance of ContractsExecResult, with status, message and contracts as parameters.
        /// </summary>
        /// <param name="status">Returned status.</param>
        /// <param name="message">Returned message.</param>
        /// <param name="contracts">Returned contracts.</param>
        public ContractsExecResult(ExecutionResults status, string message, Contract[] contracts)
        {
            this.status = status;
            this.message = message;
            this.contracts = new List<Contract>(contracts);
        }

        /// <summary>
        /// Create new instance of ContractsExecResult, with an Exception as parameter.
        /// </summary>
        /// <param name="ex">Returned Exception</param>
        public ContractsExecResult(Exception ex)
        {
            status = ExecutionResults.Failed;
            message = ex.Message;
        }

        private List<Contract> contracts;
        /// <summary>
        /// Holders of returned contracts.
        /// </summary>
        public List<Contract> Contracts
        {
            get { return contracts; }
            set { contracts = value; }
        }

        #region IExecResult Members

        ExecutionResults status;
        /// <summary>
        /// IExecResult.Status implementation, see <see cref="IExecResult.Status">IExecResult.Status</see> for more information.
        /// </summary>
        public ExecutionResults Status
        {
            get { return status; }
            set { status = value; }
        }

        string message;
        /// <summary>
        /// IExecResult.Message implementation, see <see cref="IExecResult.Message">IExecResult.Message</see> for more information.
        /// </summary>
        public string Message
        {
            get { return message; }
            set { message = value; }
        }

        #endregion
    }

 
    /// <summary>
    /// Object that will be returned which contains Users Contracts Execution Results. 
    /// </summary>
    public class UsersContractsExecResult : IExecResult
    {
        /// <summary>
        /// Create new instance of UsersContractsExecResult.
        /// </summary>
        public UsersContractsExecResult()
        {
        }

        /// <summary>
        /// Create new instance of UsersContractsExecResult, with status and message as parameters.
        /// </summary>
        /// <param name="status">Returned status.</param>
        /// <param name="message">Returned message.</param>
        public UsersContractsExecResult(ExecutionResults status, string message)
        {
            this.status = status;
            this.message = message;
        }

        /// <summary>
        /// Create new instance of UsersContractsExecResult, with status, message and contracts as parameters.
        /// </summary>
        /// <param name="status">Returned status.</param>
        /// <param name="message">Returned message.</param>
        /// <param name="contracts">Returned contracts.</param>
        public UsersContractsExecResult(ExecutionResults status, string message, UserContract[] contracts)
        {
            this.status = status;
            this.message = message;
            this.userContracts = new List<UserContract>(contracts);
        }

        /// <summary>
        /// Create new instance of UsersContractsExecResult, with an Exception as parameter.
        /// </summary>
        /// <param name="ex">Returned exception.</param>
        public UsersContractsExecResult(Exception ex)
        {
            status = ExecutionResults.Failed;
            message = ex.Message;
        }

        private List<UserContract> userContracts;
        /// <summary>
        /// Holder of returned contracts.
        /// </summary>
        public List<UserContract> UserContracts
        {
            get { return userContracts; }
            set { userContracts = value; }
        }

        #region IExecResult Members

        ExecutionResults status;
        /// <summary>
        /// IExecResult.Status implementation, see <see cref="IExecResult.Status">IExecResult.Status</see> for more information.
        /// </summary>
        public ExecutionResults Status
        {
            get { return status; }
            set { status = value; }
        }

        string message;
        /// <summary>
        /// IExecResult.Message implementation, see <see cref="IExecResult.Message">IExecResult.Message</see> for more information.
        /// </summary>
        public string Message
        {
            get { return message; }
            set { message = value; }
        }

        #endregion
    }

    ///// <summary>
    ///// Object that will be returned which contains Supports Execution Results. 
    ///// </summary>
    //public class SupportsExecResult : IExecResult
    //{
    //    /// <summary>
    //    /// Create new instance of SupportsExecResult.
    //    /// </summary>
    //    public SupportsExecResult()
    //    {
    //    }

    //    /// <summary>
    //    /// Create new instance of SupportsExecResult, with status and message as parameters.
    //    /// </summary>
    //    /// <param name="status">Returned status.</param>
    //    /// <param name="message">Returned message.</param>
    //    public SupportsExecResult(ExecutionResults status, string message)
    //    {
    //        this.status = status;
    //        this.message = message;
    //    }

    //    /// <summary>
    //    /// Create new instance of SupportsExecResult, with status, message and supports as parameters.
    //    /// </summary>
    //    /// <param name="status">Returned status.</param>
    //    /// <param name="message">Returned message.</param>
    //    /// <param name="supports">Returned supports.</param>
    //    public SupportsExecResult(ExecutionResults status, string message, UserSupport[] supports)
    //    {
    //        this.status = status;
    //        this.message = message;
    //        this.supports = new List<UserSupport>(supports);
    //    }

    //    /// <summary>
    //    /// Create new instance of SupportsExecResult, with an Exception as parameter.
    //    /// </summary>
    //    /// <param name="ex">Returned Exception.</param>
    //    public SupportsExecResult(Exception ex)
    //    {
    //        status = ExecutionResults.Failed;
    //        message = ex.Message;
    //    }

    //    private List<UserSupport> supports;
    //    /// <summary>
    //    /// Holder of returned supports.
    //    /// </summary>
    //    public List<UserSupport> Supports
    //    {
    //        get { return supports; }
    //        set { supports = value; }
    //    }

    //    #region IExecResult Members

    //    ExecutionResults status;
    //    /// <summary>
    //    /// IExecResult.Status implementation, see <see cref="IExecResult.Status">IExecResult.Status</see> for more information.
    //    /// </summary>
    //    public ExecutionResults Status
    //    {
    //        get { return status; }
    //        set { status = value; }
    //    }

    //    string message;
    //    /// <summary>
    //    /// IExecResult.Message implementation, see <see cref="IExecResult.Message">IExecResult.Message</see> for more information.
    //    /// </summary>
    //    public string Message
    //    {
    //        get { return message; }
    //        set { message = value; }
    //    }

    //    #endregion
    //}

    ///// <summary>
    ///// Object that will be returned which contains Users Supports Execution Results. 
    ///// </summary>
    //public class UsersSupportsExecResult : IExecResult
    //{
    //    /// <summary>
    //    /// Create new instance of UsersSupportsExecResult.
    //    /// </summary>
    //    public UsersSupportsExecResult()
    //    {
    //    }

    //    /// <summary>
    //    /// Create new instance of UsersSupportsExecResult, with status and message as parameters.
    //    /// </summary>
    //    /// <param name="status">Returned status.</param>
    //    /// <param name="message">Returned message.</param>
    //    public UsersSupportsExecResult(ExecutionResults status, string message)
    //    {
    //        this.status = status;
    //        this.message = message;
    //    }

    //    /// <summary>
    //    /// Create new instance of UsersSupportsExecResult, with status, message and supports as parameters.
    //    /// </summary>
    //    /// <param name="status">Returned status.</param>
    //    /// <param name="message">Returned message.</param>
    //    /// <param name="supports">Returned supports.</param>
    //    public UsersSupportsExecResult(ExecutionResults status, string message, UserSupport[] supports)
    //    {
    //        this.status = status;
    //        this.message = message;
    //        this.userSupports = new List<UserSupport>(supports);
    //    }

    //    /// <summary>
    //    /// Create new instance of ProductUsersProductsExecResultsExecResult, with an Exception as parameter.
    //    /// </summary>
    //    /// <param name="ex">Returned Exception</param>
    //    public UsersSupportsExecResult(Exception ex)
    //    {
    //        status = ExecutionResults.Failed;
    //        message = ex.Message;
    //    }

    //    private List<UserSupport> userSupports;
    //    /// <summary>
    //    /// Holder of returned supports.
    //    /// </summary>
    //    public List<UserSupport> UserSupports
    //    {
    //        get { return userSupports; }
    //        set { userSupports = value; }
    //    }

    //    #region IExecResult Members

    //    ExecutionResults status;
    //    /// <summary>
    //    /// IExecResult.Status implementation, see <see cref="IExecResult.Status">IExecResult.Status</see> for more information.
    //    /// </summary>
    //    public ExecutionResults Status
    //    {
    //        get { return status; }
    //        set { status = value; }
    //    }

    //    string message;
    //    /// <summary>
    //    /// IExecResult.Message implementation, see <see cref="IExecResult.Message">IExecResult.Message</see> for more information.
    //    /// </summary>
    //    public string Message
    //    {
    //        get { return message; }
    //        set { message = value; }
    //    }

    //    #endregion
    //}

    /// <summary>
    /// PurchaseAndBillingManagement implementation, see <see cref="IPurchasingManagement"/> for more information.
    /// </summary>
    public partial class Session : IPurchasingManagement
    {
        #region IPurchasingManagement Members
        /// <summary>
        /// IPurchasingManagement.GetAllProducts implementation, see <see cref="IPurchasingManagement.GetAllProducts()">IPurchasingManagement.GetAllProducts</see> for more information.
        /// </summary>
        /// <returns>Will return Products Execution Result, see <see cref="ProductsExecResult"/>.</returns>
        ProductsExecResult IPurchasingManagement.GetAllProducts()
        {
            if (service == null || service.State == System.ServiceModel.CommunicationState.Closed)
                service = new DiomedeStorageClient();
            try
            {
                Product[] products = service.GetAllProducts();
                return new ProductsExecResult(ExecutionResults.Success, "Get all products successful.", products);
            }
            catch (Exception ex)
            {
                return new ProductsExecResult(ex);
            }
        }

        /// <summary>
        /// IPurchasingManagement.GetAllProducts implementation, see <see cref="IPurchasingManagement.GetMyProducts()">IPurchasingManagement.GetMyProducts</see> for more information.
        /// </summary>
        /// <returns>Will return Users Products Execution Result, see <see cref="UsersProductsExecResult"/></returns>
        UsersProductsExecResult IPurchasingManagement.GetMyProducts()
        {
            if (service == null || string.IsNullOrEmpty(token))
                return new UsersProductsExecResult(Enums.ExecutionResults.Failed, "No active user.");
            try
            {
                UserProduct[] products = service.GetMyProducts(token);
                return new UsersProductsExecResult(ExecutionResults.Success, "Get my products successful.", products);
            }
            catch (Exception ex)
            {
                return new UsersProductsExecResult(ex);
            }
        }

        /// <summary>
        /// IPurchasingManagement.PurchaseProduct implementation, see <see cref="IPurchasingManagement.PurchaseProduct(int)">IPurchasingManagement.PurchaseProduct</see> for more information.
        /// </summary>
        /// <param name="productID">Product ID</param>
        /// <returns>Will return Products Execution Result, see <see cref="ProductsExecResult"/>.</returns>
        ProductsExecResult IPurchasingManagement.PurchaseProduct(int productID)
        {
            if (service == null || string.IsNullOrEmpty(token))
                return new ProductsExecResult(Enums.ExecutionResults.Failed, "No active user.");
            try
            {
                service.PurchaseProduct(token, productID);
                return new ProductsExecResult(ExecutionResults.Success, "Purchase product successful.");
            }
            catch (Exception ex)
            {
                return new ProductsExecResult(ex);
            }

        }

        /// <summary>
        /// IPurchasingManagement.CancelProduct implementation, see <see cref="IPurchasingManagement.CancelProduct(int)">IPurchasingManagement.CancelProduct</see> for more information.
        /// </summary>
        /// <param name="userProductID">Product ID.</param>
        /// <returns>Will return Products Execution Result, see <see cref="ProductsExecResult"/>.</returns>
        ProductsExecResult IPurchasingManagement.CancelProduct(int userProductID)
        {
            if (service == null || string.IsNullOrEmpty(token))
                return new ProductsExecResult(Enums.ExecutionResults.Failed, "No active user.");
            try
            {
                service.CancelProduct(token, userProductID);
                return new ProductsExecResult(ExecutionResults.Success, "Cancel product successful.");
            }
            catch (Exception ex)
            {
                return new ProductsExecResult(ex);
            }
        }

        /// <summary>
        /// IPurchasingManagement.GetAllContracts implementation, see <see cref="IPurchasingManagement.GetAllContracts()">IPurchasingManagement.GetAllContracts</see> for more information.
        /// </summary>
        /// <returns>Will return Contracts Execution Result, see <see cref="ContractsExecResult"/>.</returns>
        ContractsExecResult IPurchasingManagement.GetAllContracts()
        {
            if (service == null || service.State == System.ServiceModel.CommunicationState.Closed)
                service = new DiomedeStorageClient();
            try
            {
                Contract[] contracts = service.GetAllContracts();
                return new ContractsExecResult(ExecutionResults.Success, "Get all contracts successful.", contracts);
            }
            catch (Exception ex)
            {
                return new ContractsExecResult(ex);
            }
        }

        /// <summary>
        /// IPurchasingManagement.GetMyContracts implementation, see <see cref="IPurchasingManagement.GetMyContracts()">IPurchasingManagement.GetMyContracts</see> for more information.
        /// </summary>
        /// <returns>Will return Users Contracts Execution Result, see <see cref="UsersContractsExecResult"/>.</returns>
        UsersContractsExecResult IPurchasingManagement.GetMyContracts()
        {
            if (service == null || string.IsNullOrEmpty(token))
                return new UsersContractsExecResult(Enums.ExecutionResults.Failed, "No active user.");
            try
            {
                UserContract[] contracts = service.GetMyContracts(token);
                return new UsersContractsExecResult(ExecutionResults.Success, "Get my contracts successful.", contracts);
            }
            catch (Exception ex)
            {
                return new UsersContractsExecResult(ex);
            }
        }

        /// <summary>
        /// IPurchasingManagement.PurchaseContract implementation, see <see cref="IPurchasingManagement.PurchaseContract(int)">IPurchasingManagement.PurchaseContract</see> for more information.
        /// </summary>
        /// <param name="contractID">Contract ID</param>
        /// <returns>Will return Contracts Execution Result, see <see cref="ContractsExecResult"/>.</returns>
        ContractsExecResult IPurchasingManagement.PurchaseContract(int contractID)
        {
            if (service == null || string.IsNullOrEmpty(token))
                return new ContractsExecResult(Enums.ExecutionResults.Failed, "No active user.");
            try
            {
                service.PurchaseContract(token, contractID);
                return new ContractsExecResult(ExecutionResults.Success, "Purchase contract successful.");
            }
            catch (Exception ex)
            {
                return new ContractsExecResult(ex);
            }
        }

        /// <summary>
        /// IPurchasingManagement.CancelContract implementation, see <see cref="IPurchasingManagement.CancelContract(int)">IPurchasingManagement.CancelContract</see> for more information.
        /// </summary>
        /// <param name="userContractID">User Contract ID</param>
        /// <returns>Will return Contracts Execution Result, see <see cref="ContractsExecResult"/>.</returns>
        ContractsExecResult IPurchasingManagement.CancelContract(long userContractID)
        {
            if (service == null || string.IsNullOrEmpty(token))
                return new ContractsExecResult(Enums.ExecutionResults.Failed, "No active user.");
            try
            {
                service.CancelContract(token, userContractID);
                return new ContractsExecResult(ExecutionResults.Success, "Cancel contract successful.");
            }
            catch (Exception ex)
            {
                return new ContractsExecResult(ex);
            }
        }

        /////// <summary>
        /////// IPurchasingManagement.GetAllSupports implementation, see <see cref="IPurchasingManagement.GetAllSupports()">IPurchasingManagement.GetAllSupports</see> for more information.
        /////// </summary>
        /////// <returns>Will return Supports Execution Result, see <see cref="SupportsExecResult"/>.</returns>
        ////SupportsExecResult IPurchasingManagement.GetAllSupports()
        ////{
        ////    if (service == null || service.State == System.ServiceModel.CommunicationState.Closed)
        ////        service = new com.diomede.services.DiomedeStorageClient();
        ////    try
        ////    {
        ////        Support[] supports = service.GetAllSupports();
        ////        return new SupportsExecResult(ExecutionResults.Success, "Get all supports successful.", supports);
        ////    }
        ////    catch (Exception ex)
        ////    {
        ////        return new SupportsExecResult(ex);
        ////    }
        ////}

        ///// <summary>
        ///// IPurchasingManagement.GetMySupports implementation, see <see cref="IPurchasingManagement.GetMySupports()">IPurchasingManagement.GetMySupports</see> for more information.
        ///// </summary>
        ///// <returns>Will return Users Support Execution Result, see <see cref="UsersSupportsExecResult"/>.</returns>
        //UsersSupportsExecResult IPurchasingManagement.GetMySupports()
        //{
        //    if (service == null || string.IsNullOrEmpty(token))
        //        return new UsersSupportsExecResult(Enums.ExecutionResults.Failed, "No active user.");
        //    try
        //    {
        //        UserSupport[] supports = service.GetMySupports(token);
        //        return new UsersSupportsExecResult(ExecutionResults.Success, "Get my supports successful.", supports);
        //    }
        //    catch (Exception ex)
        //    {
        //        return new UsersSupportsExecResult(ex);
        //    }
        //}

        ///// <summary>
        ///// IPurchasingManagement.PurchaseSupport implementation, see <see cref="IPurchasingManagement.PurchaseSupport(int)">IPurchasingManagement.PurchaseSupport</see> for more information.
        ///// </summary>
        ///// <param name="supportID">Support ID</param>
        ///// <returns>Will return Products Execution Result, see <see cref="ProductsExecResult"/>.</returns>
        //SupportsExecResult IPurchasingManagement.PurchaseSupport(int productID)
        //{
        //    if (service == null || string.IsNullOrEmpty(token))
        //        return new SupportsExecResult(Enums.ExecutionResults.Failed, "No active user.");
        //    try
        //    {
        //        service.PurchaseProductSupport(token, productID);
        //        return new SupportsExecResult(ExecutionResults.Success, "Purchase support successful.");
        //    }
        //    catch (Exception ex)
        //    {
        //        return new SupportsExecResult(ex);
        //    }
        //}

        ///// <summary>
        ///// IPurchasingManagement.CancelSupport implementation, see <see cref="IPurchasingManagement.CancelSupport(int)">IPurchasingManagement.CancelSupport</see> for more information.
        ///// </summary>
        ///// <param name="userSupportID">User Support ID</param>
        ///// <returns>Will return Supports Execution Result, see <see cref="SupportsExecResult"/>.</returns>
        //SupportsExecResult IPurchasingManagement.CancelSupport(int userSupportID)
        //{
        //    if (service == null || string.IsNullOrEmpty(token))
        //        return new SupportsExecResult(Enums.ExecutionResults.Failed, "No active user.");
        //    try
        //    {
        //        service.CancelSupport(token, userSupportID);
        //        return new SupportsExecResult(ExecutionResults.Success, "Cancel support successful.");
        //    }
        //    catch (Exception ex)
        //    {
        //        return new SupportsExecResult(ex);
        //    }
        //}

        

        #endregion
    }

    #endregion
}
